<!-- js call TinyMCE -->
<script type="text/javascript">
	call('description');
	call('content');
</script>

<!-- js validate form  -->
<script type="text/javascript">
$(document).ready(function() {
	$("#add").validate();		
});	
$.metadata.setType("attr", "validate");
</script>
<!-- js ajax -->
<script type="text/JavaScript">
	$(document).ready(function(){
		$('#parent_id').change(function(){	    
			$.post(		
				'<?php echo base_url(); ?>back_end/product/load',
				{
					parent_id: $('#parent_id').val(),
					id_pp:   $('#id_pp').val(),
				},
				
				function (data)
				{
					$('#load').html(data);
				}
					
			);
		});
	});
</script>
<div id="result">
</div>
            <div class="header2">
                <p class="pHead"><?php echo $title;?></p>
                <img src="images/icon/back.png" class="iconBack" alt="icon" />
                <span class="back"><a href="#">Quay lại trang trước</a></span>
            </div>
            
            <form method="POST"  name="edit" id="add" enctype="multipart/form-data">
            <div class="contentMain">
	            	<div class="contentSearch">            	
	            	<table class="tableSearch">
	                	<tr>
	                    	<td class="tdSearch">Tên sản phẩm:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text" class="required inputText" id="name" name="name" value="<?php echo $admin_product['name']; ?>">
	                    		
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">Danh mục sản phẩm:</td>
	                    	<td class="tdSearch2">
	                    		<select name="parent_id" id="parent_id" class="selectText">
	                            	<option value="0">------------------------- Chọn danh mục sản phẩm -------------------------</option>
	                            	<?php foreach ($list_menu as $key=>$value) {?>
									<option value="<?php echo $key; ?>"  <?php if($admin_product['category_product_id'] == $key) {echo 'selected=selected';} ?> ><?php echo $value; ?></option>		                            	
                           			<?php }?>
	                            </select>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">
	                    		Thuộc tính sản phẩm :
                            	<input type="hidden" name="id_pp" id="id_pp" value="<?php echo $admin_product['id']; ?>">	   
                            </td>
	                    	<td class="tdSearch2" id="load" class="tdSearch">
	                    		<table>
									<?php foreach ($pp as $pp_value) { ?>
									<tr>
										<td style="width: 150px; text-align: left;">
											<span style="color: #cf2e17; font-weight: bold;"> 
												<?php 
													echo $pp_value['name'].' :'; 
												?>
											</span>
										</td>
										
										<td style="width: 200px; text-align: left;">	
											<input style="width: 183px; padding-left: 4px; border: 1px solid #CCC;" type="text" value="<?php echo $pp_value['value'];?>" name="properties_name[<?php echo $pp_value['properties_id'];?>]"  />
										</td>
									</tr>	
									<?php } ?>
								</table>
	                    	</td>
	                    </tr>
	                    <tr>
                    		<td class="tdSearch" style="vertical-align: top;">Mô tả sản phẩm:</td>
                    		<td class="tdSearch2">
                    			<textarea id="description" name="description" class="textArea1"><?php echo $admin_product['description']; ?></textarea>
                    		</td>
                    	</tr>
                    	<tr>
                    		<td class="tdSearch" style="vertical-align: top;">Hướng dẫn sử dụng:</td>
                    		<td class="tdSearch2">
                    			<textarea id="content" name="help" class="textArea1"><?php echo $admin_product['help']; ?></textarea>
                    		</td>
                    	</tr>
                    	<tr>
	                    	<td class="tdSearch">Giá sản phẩm:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text" value="<?php echo $admin_product['cost']; ?>" class="required inputText" id="cost" name="cost">
	                    		<span>(VD: 2000000 - 2 triệu)</span>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">Giá mới sản phẩm:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text"  value="<?php echo $admin_product['cost_new']; ?>" class=" required inputText" id="cost_new" name="cost_new">
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">Mã sản phẩm:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text"  value="<?php echo $admin_product['product_code']; ?>" class=" required inputText" id="product_code" name="product_code">
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">Số lượng:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text" value="<?php echo $admin_product['quantity']; ?>" class=" required inputText" id="quantity" name="quantity">
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">Khuyến mại:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text" value="<?php echo $admin_product['km']; ?>" class="inputText" name="km">
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">Vận chuyển:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text" value="<?php echo $admin_product['vc']; ?>" class="inputText" name="vc">
	                    	</td>
	                    </tr>
	                     <tr>
	                    	<td class="tdSearch">VAT:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text" value="<?php echo $admin_product['vat']; ?>" class="inputText" name="vat">
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">Số lượng:</td>
	                    	<td class="tdSearch2">
	                    		<input type="text" value="<?php echo $admin_product['quantity']; ?>" class=" required inputText" id="quantity" name="quantity">
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">- Sản phẩm nổi bật :</td>
	                    	<td class="tdSearch2">
                    			<input type="checkbox" name="hot" value="1" class="inputCheck" <?php if ($admin_product['hot'] == 1){ echo "checked=checked"; }?>>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">- Sản phẩm mới :</td>
	                    	<td class="tdSearch2">
                    			<input type="checkbox" name="new" value="1" class="inputCheck" <?php if ($admin_product['new'] == 1){ echo "checked=checked"; }?>>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch">- Sản phẩm khuyến mại :</td>
	                    	<td class="tdSearch2">
                    			<input type="checkbox" name="promotion" value="1"  class="inputCheck" <?php if ($admin_product['new'] == 1){ echo "checked=checked"; }?>>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch" style="vertical-align: top;">Ảnh đại diện của sản phẩm:</td>
	                    	<td class="tdSearch2">
	                    		<?php if ($admin_product['image'] !== '') { ?>
                                        <img class="img_news"  alt="<?php echo $admin_product['image']; ?>" src="<?php echo base_url() ?>images/img_product/<?php echo $admin_product['image']; ?>" />
	                    		<?php } else {?>
                    					<img class="img_news" style="border: 1px solid #ededed;"  alt="<?php echo $admin_product['image']; ?>" src="<?php echo base_url() ?>images/back_end/noimg.jpg"/>
	                    		<?php }?>
	                    	</td>
	                    </tr>
	                    <tr>
                    		<td class="tdSearch" style="vertical-align: top;">Thay đổi ảnh đại diện:</td>
                    		<td class="tdSearch2">
                    			<input type="file" class="" id="images" value="" name="image">
                    		</td>
                    	</tr>
	                    <tr>
	                    	<td class="tdSearch">Trạng thái:</td>
	                    	<td>
                    			<input type="checkbox" name="status" class="inputCheck" <?php if ($admin_product['status'] == 1){ echo "checked=checked"; }?>>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch" style="vertical-align: top; padding-top: 40px; text-decoration: underline;">Các ảnh khác của sản phẩm:</td>
	                    </tr>
	                  
	                    <?php $i = 0; foreach ($product_images as $arr_prd) {
	                    	$i++; 
	                    ?>		
	                     <tr>
	                    	<td class="tdSearch" style="vertical-align: top;">Ảnh sản phẩm <?php echo $i; ?>:</td>
	                    	<td class="tdSearch2">
	                    		<?php if ($arr_prd['image'] !== '') { ?>
                                        <img class="img_news"  alt="<?php echo $arr_prd['image']; ?>" src="<?php echo base_url() ?>images/img_product/<?php echo $arr_prd['image']; ?>" />
	                    		<?php } else {?>
                    					<img class="img_news" style="border: 1px solid #ededed;"  alt="<?php echo $arr_prd['image']; ?>" src="<?php echo base_url() ?>images/back_end/noimg.jpg"/>
	                    		<?php }?>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td class="tdSearch" style="vertical-align: top;">Thay đổi ảnh <?php echo $i; ?>:</td>
	                    	<td class="tdSearch2">
	                    		<input type="file" class=""  value="" name="image_<?php echo $arr_prd['id']; ?>" />
	                    	</td>
	                    </tr>
	                    <?php } ?>
                       <tr>
	                    	<td colspan="2" style="border-top: 1px dotted #000; height: 1px; width: 100%;"></td>
	                    </tr>
	                    <?php
	                    	$ct = 5 - count($product_images);
	                    	$ct_img = count($product_images); 
	                    ?>
	                    <?php
	                    	for ($j = 1; $j <= $ct; $j++) {
						?>
							<tr>
		                    	<td class="tdSearch" style="vertical-align: top;">Ảnh <?php echo $j+$ct_img ;?>:</td>
		                    	<td class="tdSearch2">
		                    		<input type="file" class=""  value="" name="image_<?php echo $j+$ct_img ;?>" />
		                    	</td>
	                  		</tr>
						<?php 
							}
						?>
	                	<tr>
	                    	<td style="padding: 20px 0px;" class="tdSearch">&nbsp;</td>
	                    	<td style="padding: 20px 0px;" class="tdSearch2">                        	
	                            <div class="searchbutton">
	                                    <input type="submit" id="addForm" class="buttonSM" value="Add" name="editForm" />
	                            </div><!-- end searchbutton -->                      	
	                            <div class="searchbutton searchReset" >
	                                    <input type="reset" class="buttonSM"  value="Reset" name="reset" />
	                            </div><!-- end searchbutton -->
	                        </td>
	                    </tr>
	                </table>
	            </div><!-- end contentSearch -->
           	</div><!-- end contentMain -->
           	</form>
     